Music Object Extension - Fades

  Contents

About This Extension

Creating realtime music remixing applications on the Web becomes even more compelling when you add the element of fading individual parts of a mix. Using this extension, not only can you easily fade in and fade out musical parts, but you can also easily fade parts from the left side of the stereo field to the right side, or vice versa. What's more, you can set up your own custom fade processes to do anything you want, including moving DHTML layers around.

What's New in the Latest Version

There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.

Getting This Extension

To get the "music-object-x-fades.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-fades.js" into an appropriate folder of the local copy of your Web site.

In case you have problems saving the file using the above link, the "music-object-x-fades.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.

Dependencies

In order to use this extension, the following JavaScript file(s) must first be sourced in...

For more information on using extensions, consult the section About Music Object Extensions.

Reference

 Name   Short Description 
Instance Methods
fadeController Lets you fade the value of the specified MIDI controller.
fadeTempo Lets you transition the song playback tempo to a new tempo over a specified time.
fadeVolumeScalar Lets you fade any of the custom volume scalars registered for an instance.
Static Methods
Music.fade Lets you initiate your own custom fade process to affect anything you desire.
Objects
Music.Fade An object that lets you store the values for a fade process and trigger the fade at any time.

Instance Methods

 fadeController

 
 CATEGORY   Instance Method 
 MODULE   Music Object Extension - Fades 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The fadeController method lets you fade the value of the specified MIDI controller.

SYNTAX    fadeController (
    MidiChannel0to16 ,
    ControllerNumber0to127 ,
    StartValueINT ,
    EndValueINT ,
    FadeTimeMsINT ,
    FadeEndCallbackFunctionorJavaScriptSTR
)

RETURN VALUE    FadeOBJ

The fadeController method lets you fade the value of the specified MIDI controller from a specified start value to a specified end value. This is useful for remix applications and allows you to, among other things, fade in or fade out the channel volume for a musical part, or even fade parts from the left side of the stereo field to the right side, or vice versa.

In order to perform a channel volume fade, just use the value 7 for the ControllerNumber0to127 parameter. For example, the statement myMusicObject.fadeController (1,7,127,0,2000) will fade out the channel volume for MIDI channel 1 over 2 seconds. In this example, notice how we are specifying the value 127 for the StartValueINT parameter. We're starting the channel volume fade from 127 because we're assuming that this is the current channel volume for MIDI channel 1. However, if we had no way of easily knowing the current channel volume for the MIDI channel we wanted to do a fade on, we could use the special value null for the StartValueINT parameter to indicate that the fade should start at the current value of the specified controller, as in myMusicObject.fadeController (1,7,null,0,2000).

In order to perform a panning fade from left to right, you would use the value 10 for the ControllerNumber0to127 parameter. For example, the statement myMusicObject.fadeController (1,10,0,127,2000) will fade the channel pan for MIDI channel from hard left to hard right 1 over 2 seconds.

For more ideas on controllers that can be faded, consult the appendix Supported MIDI Controllers.

SPECIAL VALUES
VARIATIONS
 fadeTempo

 
 CATEGORY   Instance Method 
 MODULE   Music Object Extension - Fades 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI 
 

The fadeTempo method lets you transition the song playback tempo to a new tempo over a specified time.

SYNTAX    fadeTempo (
    StartTempoBPM0to300 ,
    EndTempoBPM0to300 ,
    FadeTimeMsINT ,
    FadeEndCallbackFunctionorJavaScriptSTR
)

RETURN VALUE    FadeOBJ

The fadeTempo method lets you transition the song playback tempo to a new tempo over a specified time. For example, the statement myMusicObject.fadeTempo (120,200,5000) will transition the tempo from the modest tempo of 120 up to the somewhat speedy tempo of 200 over 5 seconds.

In this example, if the current tempo of the instance wasn't already set to 120 at the time of the fade, then there might be a noticeable "hiccup" as the tempo fade is triggered. If we had no way of easily knowing the current tempo for the instance, then we could use the special value null for the StartTempoBPM0to300 parameter to indicate that the tempo fade should start at the current tempo value, as in myMusicObject.fadeTempo (null,200,5000).

SPECIAL VALUES
VARIATIONS
 fadeVolumeScalar

 
 CATEGORY   Instance Method 
 MODULE   Music Object Extension - Fades 
 Min. Player Version   1.0.0 
 File Types Supported   RMF, MIDI, WAV, AIFF, AU 
 

The fadeVolumeScalar method lets you fade any of the custom volume scalars that are registered for a Music Object instance.

SYNTAX    fadeVolumeScalar (
    VolumeScalarNameSTR ,
    StartVolume0to100 ,
    EndVolume0to100 ,
    FadeTimeMsINT ,
    FadeEndCallbackFunctionorJavaScriptSTR ,
    FadeStepCallbackFunctionorJavaScriptSTR
)

RETURN VALUE    FadeOBJ

SPECIAL VALUES
VARIATIONS
Static Methods

 Music.fade

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Fades 
 Min. Player Version   n/a 
 

The Music.fade static method lets you initiate your own custom fade process to affect anything you desire.

SYNTAX    Music.fade (
    FadeNameSTR ,
    StartValueINT ,
    EndValueINT ,
    FadeTimeMsINT ,
    UpdateHandlerFunctionorJavaScriptSTR ,
    FadeEndCallbackFunctionorJavaScriptSTR ,
    EndIfInProgressBOOL
)

RETURN VALUE    FadeOBJ

The FadeNameSTR parameter is a unique identifier for the fade you wish to initiate. This allows the fade to be triggered multiple times without Music Object assigning new fade tasks. This is essential if one wishes to do things like fade the tempo or fade the volume of an instance. It doesn't make all that much sense to have multiple fade tasks in progress that are all fighting with each other to set the same parameter. For instance, it wouldn't make any sense to have three separate fade tasks in progress that are fading in completely different directions, yet are all trying to set the player volume.

The UpdateHandler parameter is used to register the function or JavaScript statements you would like executed each time the fade value is updated. If you register a function as the update handler, then this function should expect to take one parameter, being the current value of the fade. If, on the other hand, you register a string statement block that is to be executed for each update, then the statements in this statement block can refer to the variable fadeValue which will be defined only for the scope of the statement block.

The FadeEndCallback parameter is used to register the function or JavaScript statements you would like executed when the fade completes. And the EndIfInProgressBOOL parameter indicates whether a pre-existing fade by the same name as that specified by the FadeNameSTR parameter should be stopped before the new fade is initiated, or whether the pre-existing fade by that name should simply be updated with the new fade settings.

Some of these principles are a little hard to explain without an example, so let's take a look at one. In the following straightforward example, we're using this method to initiate a tempo fade for the Music Object instance "myMusicObject"...

Music.fade (
   'myMusicObject_fadeTempo',
   120,
   200,
   5000,
   'myMusicObject.setTempo (fadeValue)'
);

What we have here is a fade that is named "myMusicObject_fadeTempo", which starts fading from the value 120 and reaches the value 200 over a period of 5 seconds. And each time the fade value is updated, the JavaScript statement myMusicObject.setTempo (fadeValue) is executed, where the variable fadeValue holds the current value for the fade. This variable only exists within the scope of this statement block, so referring to it elsewhere in the code may cause errors.

Notice how we haven't specified the FadeEndCallback or EndIfInProgressBOOL parameters in this example. This is because there are variations of this method (see below) where it is not necessary to specify these parameters. Now, of course, we could have used the ready-made fadeTempo instance method to achieve the same results as we have here, but this is just an example to illustrate how the Music.fade static method is used.

VARIATIONS
Objects

 Music.Fade

 
 CATEGORY   Object Constructor 
 MODULE   Music Object Extension - Fades 
 Min. Player Version   n/a 
 File Types Supported   n/a 
 

The Music.Fade object lets you store the values for a fade process and trigger the fade at any time.

SYNTAX    Music.Fade (
    StartValueINT ,
    EndValueINT ,
    FadeTimeMsINT ,
    UpdateHandlerFunctionorJavaScriptSTR ,
    FadeEndCallbackFunctionorJavaScriptSTR ,
    RestoreStartValueBOOL
)

RETURN VALUE    FadeOBJ

The UpdateHandler parameter is used to register the function or JavaScript statements you would like executed each time the fade value is updated. If you register a function as the update handler, then this function should expect to take one parameter, being the current value of the fade. If, on the other hand, you register a string statement block that is to be executed for each update, then the statements in this statement block can refer to the variable fadeValue which will be defined only for the scope of the statement block.

The FadeEndCallback parameter is used to register the function or JavaScript statements you would like executed when the fade completes. And the RestoreStartValueBOOL parameter indicates whether or not the registered update handler should be called when the fade completes with the initial fade start value as a parameter, allowing whatever was being affected by the fade to be reset to its start value.

Constructor
Instance Methods
Instance Properties

Following is a simple example of how the Music.Fade object could be used...

myTempoFade = new Music.Fade (
   120,
   200,
   5000,
   'myMusicObject.setTempo (fadeValue)'
);

myTempoFade.start ();

In this example, we are creating an instance of a Music.Fade object for the purpose of fading the tempo of the Music Object instance "myMusicObject" from the value 120 to the value 200 over a period of 5 seconds. Each time the fade value is updated, the JavaScript statement myMusicObject.setTempo (fadeValue) is executed, where the variable fadeValue holds the current value for the fade. This variable only exists within the scope of this statement block, so referring to it elsewhere in the code may cause errors.

Notice how we haven't specified the FadeEndCallback or RestoreStartValueBOOL parameters in the Music.Fade constructor in this example. This is because there are variations of the constructor (see below) where it is not necessary to specify these parameters. Although we could have used the ready-made fadeTempo instance method to achieve the same results as we have here, this is just an example to illustrate how the Music.Fade object is used.

VARIATIONS